<?php  	
	//session_start();
	
	require_once("includes/header.php"); 
	require_once("include_dao.php");
	
	if (isset($_GET['filter']))
		$action = $_GET['filter'];
	else
		$action = "empty";
	
	switch($action){
	
		case "today":
			$arrRentals = DAOFactory::getRentalsDAO()->queryByRentalsDate(date('Y-m-d'));	
		break;
		
		case "all":
			$arrRentals = DAOFactory::getRentalsDAO()->queryAll();				
		break;
		
		case "empty":
			$arrRentals = DAOFactory::getRentalsDAO()->queryAll();				
		break;
	}	
?>

<div id="mlist">
    <div id="main">    
     	
        <!-- Listado de peliculas -->        
        <div class="rightside">
        <?php	
			if(isset($_GET["err"])){
				if ($_GET["err"] != ''){
					echo("<marquee>");
					// Mensajes de error 		
						$msn =  msn_error($_GET["err"]);
						echo($msn);
					// Fin de Mensajes de Error			
					echo("</marquee>");
				}
			}
		?>
            <ul class="list">
                </br>
                <li>
                	<?php 	
						if(isset($arrRentals)){
							for($i=0;$i<count($arrRentals);$i++){							
								$row = $arrRentals[$i];
								$arrRentalsDetail = DAOFactory::getRentalsdetailDAO()->queryByFKRentals($row->pKRentals);
								print("
									<a href=''>
										<div class='box'>
											<div class='clearl'></div>
											<div class='ano'> Dia de Alquiler:".$row->rentalsDate." &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
															."Dia de Devoluci&oacute;n:" .$row->returnDate. " </div>
											<div class='txt'>"
								);
								
								echo "<table border=0 cellspacing=5 cellpadding=3 width='95%' align='center'>";
                                    
                                    
                                    echo "<tr>";
                                        echo "<td align='center'>Nombre</td>";
                                        echo "<td align='center'>Comentarios</td>";
                                        echo "<td colspan=2 align='right'>Monto</td>";
                                    echo "</tr>";
									
									echo "<tr>";
                                        echo "<td colspan=5><hr></td>";
                                    echo "</tr>";
									
								for($m=0;$m<count($arrRentalsDetail);$m++){
									$rowDetail = $arrRentalsDetail[$m];	
									
									$arrMovie = DAOFactory::getMovieDAO()->load($rowDetail->fKMovie);
									
									echo "<tr>";
									echo "<td align='left'> ".$arrMovie->name." </td>";
									
									echo "<td align='center'>";
									echo $rowDetail->comment;
									echo "</td>";
									
									echo "<td align='right' style='margin-left:10px'> $ ";
									echo $rowDetail->cost;
									echo "</tr>";
																		
								}
								
								echo "<tr><td colspan='5'><hr></td></tr>";
								echo "</table>";
								
								$arrPartner = DAOFactory::getPartnerDAO()->load($row->fKPartner);
								$arrPartnerEmployee = DAOFactory::getPartnerDAO()->load($row->fKPartnerEmployee);
								
								print("</div>
											<div class='rep'>
												<b>Cliente:</b> 
												<span class='reparto'>".$arrPartner->name."</span>
												&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
												<b>Empleado:</b> 
												<span class='reparto'>".$arrPartnerEmployee->name."</span>
												
											</div>
											<div class='in'> Descuento: 
												<span class='genero'> $ ".$row->descunt."</span> | 
															 Monto total:
												<span class='genero'> $ ".$row->totalAmount."</span>
											</div>
										</div>
										<div class='clearl'></div>
									</a>								
									<hr></br>");
							}
						}

					?>
                    
                    
                </li>
            </ul>
        </div>
                
        <div class="clear"></div>
        
    </div>
</div>     

<?php	
		require_once("includes/footer.php");	
?>